package ia;

import java.awt.Color;
import java.awt.Graphics;
import java.io.Serializable;

import graphics.DebugDrawable;

public class Link implements DebugDrawable, Serializable {
	private static final long serialVersionUID = 1L;
	private Checkpoint[] checks;
	private float distance;
	
	
	public Link() {
		checks = new Checkpoint[2];
		checks[0] = null;
		checks[1] = null;
		distance = 0f;
	}
	
	
	public void addCheckpoint(Checkpoint cp) {
		if(checks[0] == null)
			checks[0] = cp;
		else if(checks[1] == null) {
			checks[1] = cp;
			distance = checks[0].coord.distance(checks[1].coord);
		}
		else
			System.err.println("Impossible d'ajouter un checkpoint.");
	}
	
	
	public Checkpoint next(Checkpoint cp) {
		if(cp != null) {
			if(cp == checks[0])
				return checks[1];
			else if(cp == checks[1])
				return checks[0];
			else
				return null;
		}
		else
			return null;	
	}
	
	
	public float getDistance() {
		return distance;
	}
	
	
	public void drawDebug(Graphics g) {
		g.setColor(Color.YELLOW);
		g.drawLine((int)checks[0].coord.x, (int)checks[0].coord.y, (int)checks[1].coord.x, (int)checks[1].coord.y);
	}

}
